﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mcmurphy.Common
{
    public static class EncodingHelper
    {
        /// <summary>
        /// 为字符串添加BOM头信息
        /// 让客户端正确识别UTF-8编码
        /// </summary>
        /// <param name="originalString"></param>
        /// <returns></returns>
        public static byte[] ConvertToUTF8BomEncodingStringBytes(string originalString)
        {
            var bom = Encoding.UTF8.GetPreamble();
            var content = Encoding.UTF8.GetBytes(originalString);
            var resultBytes = new byte[bom.Length + content.Length];
            bom.CopyTo(resultBytes, 0);
            content.CopyTo(resultBytes, bom.Length);
            return resultBytes;
        }
    }
}
